package com.test01_程序基础;

import org.junit.Test;

/**
 * 分支结构
 */
public class YootkDemo_04 {

    @Test
    public void test1() {
        int age = 25;
        if (age >= 18) {
            System.out.println("成年人");
        } else {
            System.out.println("未成年人");
        }
    }

    @Test
    public void test2() {
        double score = 90.00;
        if (score >= 90 && score <= 100) {
            System.out.println("优等生");
        } else if (score >= 60 && score < 90) {
            System.out.println("良等生");
        } else {
            System.out.println("差等生");
        }
    }

    @Test
    public void test3() {
        int ch = 1;
        switch (ch) {
            case 1:
                System.out.println("【1】匹配的数字：1");
                break;
            case 2:
                System.out.println("【2】匹配的数字：2");
                break;
            default:
                System.out.println("【NO】无法匹配的内容");
        }
    }

    /**
     * yield局部返回
     * JDK13引入
     */
    @Test
    public void test4() {
        String data = "one";
        /*{
            int result = switch (data) {
                case "one": yield 1;
                case "two": yield 2;
                default: yield - 1;
            };
            System.out.println(result);
        }*/
        /*{
            int result = switch (data) {
                case "one" -> 1;
                case "two" -> 2;
                default -> -1;
            };
            System.out.println(result);
        }*/
    }
}
